﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using TagCore;

namespace TagManager
{
    public partial class ResultControl : UserControl
    {
        private IMusicData md;
        public event ResultDataHandler ResultData;

        public ResultControl()
        {
            InitializeComponent();
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
        }

        public void Display(IMusicData md)
        {
            this.md = md;
            txtAlbum.Text = md.Album;
            txtYear.Text = md.Year.ToString();
            txtAlbumArtist.Text = TagCoreUtil.CombineStrings(md.AlbumArtists);
            txtArtist.Text = TagCoreUtil.CombineStrings(md.Artists);
            txtTitle.Text = md.Title;
            txtTrack.Text = md.Track.ToString();
            txtGenre.Text = md.Genre;
            if (md.Image != null && md.Image.Length > 0)
            {
                try
                {
                    pictureBox1.Image = Image.FromStream(new MemoryStream(md.Image));
                }catch{}
            }
        }


        private void txtTitle_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Title));
        }

        private void txtAlbum_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Album));
        }
        private void txtYear_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Year));
        }
        private void txtArtist_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Artist));
        }

        private void txtAlbumArtist_DoubleClick(object sender, EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.AlbumArtist));
        }

        private void txtTrack_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Track));
        }

        private void pictureBox1_DoubleClick(object sender, System.EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Image));
        }

        private void txtGenre_DoubleClick(object sender, EventArgs e)
        {
            if (ResultData != null)
                ResultData(this, new ResultDataEventArgs(md, QueryFields.Genre));
        }
    }
}
